package com.onesports.intelligent.k12.polarlight.controller.organization.order;

import cn.gjing.excel.executor.ExcelFactory;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.organization.OrgPageOrderDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.market.TotalDataVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.order.OrderByIdVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.order.OrgOrderPageVO;
import com.onesports.intelligent.k12.polarlight.service.order.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * @author chenrl
 **/
@Api(tags = "机构端-财务管理-课程订单")
@RestController
@RequiredArgsConstructor
@RequestMapping(ApiPathConstants.ORGORDER)
public class OrgOrderController {

    private final OrderService orderService;

    @ApiOperation("机构端-分页查询订单信息")
    @GetMapping("/select-page")
    public ResponseEntity<TotalDataVO<OrgOrderPageVO>> selectPage(@Valid OrgPageOrderDTO orgPageOrderDTO) {
        return ResultUtil.success(orderService.selectOrgTotal(new Page<OrgOrderPageVO>(orgPageOrderDTO.getPage(),orgPageOrderDTO.getRow()),orgPageOrderDTO));
    }
    @ApiOperation("机构端-订单导出")
    @GetMapping("/export")
    public void export(HttpServletResponse response, OrgPageOrderDTO dto) {
        List<OrgOrderPageVO> orgOrderPageVOS = orderService.selectOrgTotalExport(dto);

        ExcelFactory.createWriter(OrgOrderPageVO.class, response)
                .write(orgOrderPageVOS).flush();
    }
    @ApiOperation("机构端根据id查询订单信息")
    @GetMapping("/select-by-id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    public ResponseEntity<OrderByIdVO> selectById(String orderNo) {
        return ResultUtil.success(orderService.selectById(orderNo));
    }

}













